package tcln.gxtx.client.utils.lang;

/**
 * Boolean utility class for GWT client-side.
 * 
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
public class GwtBooleanUtils {

    /**
     * Gets boolean value from an object {@link Boolean} with specified default if given object is <code>null</code>.
     * 
     * @param bool
     *            Boolean value as object.
     * @param valueIfNull
     *            value if given object is <code>null</code>.
     * @return Given boolean value or <b>valueIfNull</b>.
     */
    public static boolean toBoolean(Boolean bool, boolean valueIfNull) {
        if (bool == null) {
            return valueIfNull;
        }
        return bool.booleanValue();
    }

    /**
     * Gets boolean value from an object {@link Boolean} with default value = <code>false</code> if given object is
     * <code>null</code>.
     * 
     * @param bool
     *            Boolean value as object.
     * @return Given boolean value or <code>false</code>.
     */
    public static boolean toBoolean(Boolean bool) {
        return toBoolean(bool, false);
    }
}
